package com.lap.framework.exception;

import java.io.Serial;
import org.apache.commons.lang3.ArrayUtils;
import com.lap.framework.dto.result.ErrorCode;
import lombok.Getter;

/**
 * 业务异常
 *
 * <ol>
 *   <li>业务校验不通过中断
 *   <li>系统异常中断参考: {@link SystemException}
 *   <li>创建参考: {@link #interrupt(ErrorCode)}
 *   <li>创建参考: {@link #interrupt(ErrorCode, Object...)}
 * </ol>
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
@Getter
public final class BizException extends AbstractException {
  @Serial
  private static final long serialVersionUID = 8190120976499364190L;
  /** 占位符参数 */
  private final transient Object[] args;

  /**
   * 全参数构造函数
   *
   * @param errorCode 消息提示
   * @param args 参数集合
   */
  private BizException(ErrorCode errorCode, Object... args) {
    super(errorCode);
    this.args = args;
  }

  public static void interrupt(ErrorCode errorCode) {
    interrupt(errorCode, ArrayUtils.EMPTY_OBJECT_ARRAY);
  }

  public static void interrupt(ErrorCode errorCode, Object... args) {
    throw new BizException(errorCode, args);
  }

  public static BizException newBiz(ErrorCode errorCode) {
    return newBiz(errorCode, ArrayUtils.EMPTY_OBJECT_ARRAY);
  }

  public static BizException newBiz(ErrorCode errorCode, Object... args) {
    return new BizException(errorCode, args);
  }
}
